
# 使用urllib访问百度
import urllib.parse
import urllib.request

url = "https://www.baidu.com/?wd="

headers = {
    "User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36"
}

url = url + urllib.parse.quote("qying")
request = urllib.request.Request(url=url, headers = headers)
response = urllib.request.urlopen(request)

print(response.read().decode('utf-8'))